package com.olympus.hermes.auth.component;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
import org.springframework.stereotype.Component;

/**
 * @author 米奇
 * @since 2020.07.23
 */
@Component
public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator<OAuth2Exception> {


    @Override
    public ResponseEntity<OAuth2Exception> translate(Exception e) {
        e.printStackTrace();
        OAuth2Exception oAuth2Exception = new OAuth2Exception(e.getMessage());
        return ResponseEntity.status(HttpStatus.OK).body(oAuth2Exception);
    }
}
